Memory management is a process of managing computer memory, including mechanisms to dynamically allocate portions of memory to programs upon request and freeing the portions of memory for reuse when no longer needed.
Programming languages such as Java, C++, Lisp, Smalltalk, and several scripting languages allocate memory from such an area known as the heap (or heap memory). At any given time, some parts of the heap may be in use while parts may be “free” (i.e., unused) and thus available for future allocations. In order to free memory from the heap, garbage collection is needed. A key problem with such environments is that memory overhead is a significant factor. Programmers cannot manually allocate or deallocate memory objects. They need to rely on garbage collectors (i.e., one or more garbage collectors are normally available in the operating system) to free up memory which is no longer being used. In many cases, this can result in excess memory being allocated to the heap.
Such excess heap memory being allocated to one or more applications operating in a computer system environment can create serious memory management problems for the computer system. These problems are particularly difficult to deal with in situations in which multiple applications are running on the same computer system, and the applications are all competing for memory. For example, one or more Java virtual machines (JVM) might be running on an information processing system (computer system) with other applications, and the objective is to allocate memory efficiently across all applications, including the Java virtual machines. The JVM should not take up more memory than it needs. Java allocates memory from an area known as the heap. In order to free memory from the heap, garbage collection is needed.
A key problem is that while garbage collection might free up a considerable amount of memory, the JVM might not give up the free memory to the operating system. Instead, the JVM might keep the free memory for itself in case the memory requirements for the JVM increase.
Garbage collection is a form of automatic memory management that attempts to reclaim “garbage”, as referring to memory occupied by objects that are no longer in use by a program. Garbage collection is often portrayed as the opposite of manual memory management, a mechanism in which the programmer specifies which objects to deallocate and return to the memory system. Many computer languages, such as Java, C++, and several scripting languages, require garbage collection either as part of the language specification or effectively for practical implementation, while other languages, such as C, C++, were designed for use with manual memory management but have garbage collected implementations available. Still others, such as Ada, Modula-3, and C++/CLI allow both garbage collection and manual memory management to co-exist in the same application by using separate heaps, and others, such as D, are garbage collected while allowing the user to manually delete objects and disable garbage collection when speed is required.
The entity that performs garbage collection is known as the garbage collector. Garbage collectors are typically implemented in software running on a computer system. They can also be implemented using special hardware that supports the garbage collector software to aid garbage collection.
In certain information processing systems, a user can manually force a JVM to give up memory (i.e., back to the operating system) that was freed during a garbage collection by adjusting a parameter known as softmx. By adjusting the value of system parameter softmx, a JVM can be forced to give up memory which has been freed by a garbage collector back to the operating system for other applications to use. A problem with this technology is that the user has to manually adjust the value of the parameter softmx to determine the right value for it so that the JVM gives memory back to the operating system. Determining the right amount of memory to give back is difficult. If too little is given back, the system will use up excess memory. If too much memory is given back, then excess CPU (processor) cycles may be consumed for giving back the memory as well as requesting additional memory later. Garbage collection overhead may also rise. In the worst case, the JVM may crash due to an out of memory error.